import { _decorator, color, Component, Label, Sprite } from 'cc';
const { ccclass, property } = _decorator;


@ccclass('Block')
export class Block extends Component {

    @property(Label)
    public numberLabel: Label = null;

    private colorMap: Map<number, string> = new Map<number, string>();

    onLoad() {
        this.initColorMap();
    }

    update(deltaTime: number) {
        
    }

    initColorMap() {
        this.colorMap.set(0, "#d3d9d1");
        this.colorMap.set(2 ** 1, "#ffc773");
        this.colorMap.set(2 ** 2, "#ffc64b");
        this.colorMap.set(2 ** 3, "#ffb61e");
        this.colorMap.set(2 ** 4, "#ffa400");
        this.colorMap.set(2 ** 5, "#d9b611");
        this.colorMap.set(2 ** 6, "#ff4c00");
        this.colorMap.set(2 ** 7, "#ff3300");
        this.colorMap.set(2 ** 8, "#ff2121");
        this.colorMap.set(2 ** 9, "#f20c00");
        this.colorMap.set(2 ** 10, "#801dae");
        this.colorMap.set(2 ** 11, "#56004f");
    }

    setNumber(num: number) {
        if (num === 0) {
            this.node.getComponent(Sprite).color = color(this.colorMap.get(0));
            this.numberLabel.node.active = false;
            return;
        }
        if (this.colorMap.has(num)) {
            this.node.getComponent(Sprite).color = color(this.colorMap.get(num));
            if (num > 8) {
                this.numberLabel.color = color("#e0f0e9");
            } else {
                this.numberLabel.color = color("#5d513c");
            }
        }
        this.numberLabel.node.active = true;
        this.numberLabel.string = num.toString();
    }

}


